package com.suyafei.component.impl;

import com.suyafei.component.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @program: suyafei-1024-shop
 * @description
 * @author: luffy
 * @create: 2021-02-24 11:27
 */
@Service
@Slf4j
public class MailServiceImpl implements MailService {
    /**
     * springboot 提供的一个发送邮件的简单抽象，直接进入即可
     */
    @Autowired
    private JavaMailSender mailSender;


    @Value("${spring.mail.from}")
    private String from;
    @Override
    public void sendMail(String to, String subject, String content) {
        //创建一个邮箱的消息对象
        SimpleMailMessage message = new SimpleMailMessage();

        //设置邮箱发件人
        message.setFrom(from);

        //邮件收件人
        message.setTo(to);
        //邮件的主题
        message.setSubject(subject);
        //邮件的内容
        message.setText(content);

        mailSender.send(message);

        log.info("邮件发送成功{}", message.toString());
    }
}
